<template>
  <el-dialog title="新增" :close-on-click-modal="false" :visible.sync="visible" width="30vw" top="8vh" @close="closeDialog()">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()"
             label-width="130px">
      <div class="boxsty">
        <el-row>
          <el-col>
            <el-form-item label="工作名称:" prop="workName">
              <el-input v-model="dataForm.workName" placeholder="工作名称"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <el-form-item label="结束时间:" prop="endDate" >
              <el-date-picker v-model="dataForm.endDate" type="date" value-format="yyyy-MM-dd"
                              placeholder="结束时间" style="width: 100%"></el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <el-form-item label="工作目标/成效:" prop="workResult">
              <el-input type="textarea" :rows="6" v-model="dataForm.workResult" placeholder="工作目标/成效"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </div>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" plain @click="saveFormData">确定</el-button>
      <el-button type="primary" plain @click="closeDialog()">返回</el-button>
    </span>
  </el-dialog>
</template>

<script>

import {saveZhuanxiang} from "@/api/hetongrenwu/zhuanxianggongzuo/zxgzchuangjian";

export default {
  components: {
  },
  data() {
    return {
      xgBz: false,
      visible: false,
      canSubmit: false,
      dataForm: {},
      dataRule: {
        workName: [
          {required: true, message: '工作名称不能为空', trigger: 'blur'}
        ],
        endDate: [
          {required: true, message: '结束时间不能为空', trigger: 'blur'}
        ],
        workResult: [
          {required: true, message: '工作目标/成效不能为空', trigger: 'blur'}
        ]
      }
    }
  },
  watch: {
  },
  methods: {
    //初始化
    csh() {
      this.dataForm = {};
    },
    init(obj) {
      if(obj){
        this.dataForm = obj;
      }
      this.visible = true;
      this.canSubmit = true;
    },
    saveFormData(){
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          saveZhuanxiang(this.dataForm).then(res=>{
            this.$message.success('保存成功')
            this.visible=false;
            this.$emit("refreshDataList")
            this.closeDialog();
          })
        } else {
         //console.log('error submit!!');
          return false;
        }
      });
    },
    closeDialog(){
      this.visible=false;
      this.$emit("closeDialog");
    }
  }
}
</script>
<style scoped>
.el-divider {
  background-color: #fff
}
.tree-box{
  height: 500px;
  overflow: auto;
}
</style>
